package com.steven.learnjava.mapper;

import com.steven.learnjava.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Delete;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("SELECT id, username, password, email FROM user")
    List<User> findAll();

    @Insert("INSERT INTO user(username, password, email) VALUES(#{username}, #{password}, #{email})")
    int insert(User user);

    @Update("UPDATE user SET password = #{newPassword} WHERE id = #{userId}")
    int updatePassword(@Param("userId") Integer userId, @Param("newPassword") String newPassword);

    @Delete("DELETE FROM user WHERE id = #{userId}")
    int deleteById(@Param("userId") Integer userId);
}
